﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JkUtils
{
    public class JkRandom
    {
        /// <summary>
        /// 生成小写字符串
        /// </summary>
        /// <param name="length">长度</param>
        /// <returns></returns>
        public static string CreateSmallString(int length)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < length; i++)
            {
                Random random = new Random(Guid.NewGuid().GetHashCode());
                int num = random.Next(97, 123);
                sb.Append(Convert.ToChar(num).ToString());
            }
            return sb.ToString();
        }


        /// <summary>
        /// 生成单个大写随机字母
        /// </summary>
        public static string CreateBigString(int length)
        {
            //A-Z的 ASCII值为65-90
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < length; i++)
            {
                Random random = new Random(Guid.NewGuid().GetHashCode());
                int num = random.Next(65, 91);
                sb.Append(Convert.ToChar(num).ToString());
            }

            return sb.ToString();
        }

        public static string CreateNum(int length) 
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < length; i++)
            {
                Random random = new Random(Guid.NewGuid().GetHashCode());
                int num = random.Next(10);
                sb.Append(num.ToString());
            }
            return sb.ToString();
        }

        public static int CreateRangeNum(int min,int max) 
        {
            Random random = new Random(Guid.NewGuid().GetHashCode());
            return random.Next(min,max);
        }
        public static string[] months = new string[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"  };
        /// <summary>
        /// 生成小写字母+数字的账号
        /// </summary>
        /// <param name="strlength">字符串长度</param>
        /// <param name="numlength">数字长度</param>
        /// <returns></returns>
        public static string CreateAccount(int strlength, int numlength)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(CreateSmallString(strlength));
            sb.Append(CreateNum(numlength));
            return sb.ToString();
        }

        public static string CreatePassword(int strlength,int numlength)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < strlength; i++)
            {
                Random random = new Random(Guid.NewGuid().GetHashCode());
                int num = random.Next(1,3);
                switch (num)
                {
                    case 1:
                        sb.Append(CreateSmallString(1));
                        break;
                    case 2:
                        sb.Append(CreateBigString(1));
                        break;
                    default:
                        sb.Append(CreateSmallString(1));
                        break;
                }
            }
            sb.Append(CreateNum(numlength));
            return sb.ToString();
        }

        public static string CreateSonyPassword()
        {
            return $"{CreatePassword(2, 1)}{CreatePassword(2, 1)}{CreatePassword(2, 1)}";
        }
    }
}
